/*
 * @(#)DaoConfig.java	1.00 10/06/25
 *
 * Copyright 2010 Kmdigit, Inc. All rights reserved.
 * KMdigit PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

package kmdigit.dao;

import java.io.Reader;
import java.util.Properties;
import com.ibatis.common.resources.Resources;
import com.ibatis.dao.client.DaoManager;
import com.ibatis.dao.client.DaoManagerBuilder;

/**
 * @author  Kyunam Lee
 * @version 1.00, 06/25/10
 */

public class DaoConfig 
{
	private static DaoConfig instance;
	private static final String resource = "dao.xml";
	private static final DaoManager daoManager = newDaoManager(null);
	
	//Singleton pattern - Constructor is private method and client approach to object that provide to public static method
	private DaoConfig(){}
	public static DaoConfig getDaoConfig()
	{ 
		if (instance == null)
			instance = new DaoConfig();
		return instance;
	}
	
	public static DaoManager getDaoManager(){ return daoManager; }
	public static DaoManager newDaoManager(Properties props)
	{
		try 
		{
			Reader reader = Resources.getResourceAsReader(resource);
			return DaoManagerBuilder.buildDaoManager(reader, props);
		}//end try
		catch (Exception e) 
		{
			throw new RuntimeException("Could not initialize DaoConfig. Cause: " + e, e);
		}//end catch
	}
}
